home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / less_14z / part03 < prev    next >
Internet Message Format  |  1991-07-08  |  60KB

  1. Path: news.larc.nasa.gov!amiga-request
  2. From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v91i129: Less 1.4Z - text pager, Part03/07
  4. Reply-To: rayz@altair.csustan.edu (R. L. Zarling)
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga.v91i129@ab20.larc.nasa.gov>
  7. References: <comp.sources.amiga.v91i127@ab20.larc.nasa.gov>
  8. Date: 04 Jul 91 17:28:18 GMT
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga.misc
  12.  
  13. Submitted-by: rayz@altair.csustan.edu (R. L. Zarling)
  14. Posting-number: Volume 91, Issue 129
  15. Archive-name: utilities/less-1.4z/part03
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 7)."
  24. # Contents:  Less1.4Z/src/io.c Less1.4Z/src/main.c
  25. #   Less1.4Z/src/screen.c
  26. # Wrapped by tadguy@ab20 on Thu Jul  4 13:28:15 1991
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'Less1.4Z/src/io.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'Less1.4Z/src/io.c'\"
  30. else
  31. echo shar: Extracting \"'Less1.4Z/src/io.c'\" \(17649 characters\)
  32. sed "s/^X//" >'Less1.4Z/src/io.c' <<'END_OF_FILE'
  33. X/*  io.c */
  34. X
  35. X#ifdef AMIGA
  36. X/* Compile with -HPreHeader.q to get "less.h"! */
  37. X#else
  38. X#include "less.h"
  39. X#endif
  40. X
  41. X#include <ctype.h>
  42. X#include <string.h>
  43. X#include <intuition/intuition.h>
  44. X#include <dos.h>
  45. X
  46. X
  47. X#undef TRUE
  48. X#undef FALSE
  49. X
  50. Xextern int sigs;
  51. X
  52. Xstatic struct  ConCom     *tty = NULL;
  53. X
  54. Xpublic int     nrow = 0;         /* Terminal size, rows.         */
  55. Xpublic int     ncol;             /* Terminal size, columns.      */
  56. X
  57. Xstatic struct Window *LessWindow;
  58. X
  59. Xint Wind_Spec[4] = { 0, 0, 0, 0 };
  60. X/* User-supplied option specifying window size/position:
  61. X *
  62. X * [0]: Left edge X - coord.
  63. X * [1]: Top edge Y - coord.
  64. X * [2]: Right edge X - coord.
  65. X * [3]: Bottom edge Y - coord.
  66. X *
  67. X * If element 2 or 3 is negative, it is taken to be a relative value to be
  68. X * subtracted from the maximum screen size.  If the resulting window
  69. X * would be smaller than the minimum, it is quietly enlarged to the
  70. X * minimum, by expanding to the lower right as far as possible, and then
  71. X * moving the window toward the upper left if necessary.
  72. X */
  73. X#define W_MINWIDTH 200
  74. X#define W_MINHEIGHT 60
  75. X
  76. Xextern char version[];
  77. X
  78. X/* Prototypes for functions defined in io.c */
  79. X
  80. Xstatic struct ConCom *OpenConsole __PROTO((struct Window *window));
  81. Xstatic void CloseConsole __PROTO((struct ConCom *tty));
  82. Xstatic void StartTtyTimer __PROTO((void));
  83. Xstatic void StartConRead __PROTO((struct ConCom *tty));
  84. Xstatic int ConGetC __PROTO((struct ConCom *tty));
  85. Xstatic int ConLookC __PROTO((struct ConCom *tty));
  86. Xstatic void ConWrite __PROTO((struct ConCom *tty,
  87. X                              char *data,
  88. X                              int length));
  89. X
  90. X
  91. X
  92. X/****************************************************************/
  93. X/* Code to open a console on an existing Intuition window.
  94. X   See RKM Libraries & Devices, pp 277 ff
  95. X*/
  96. X
  97. X#include <exec/memory.h>
  98. X#include <devices/timer.h>
  99. X
  100. Xextern struct GfxBase *GfxBase;
  101. Xextern struct IOStdReq * CreateStdIO();
  102. Xextern struct MsgPort *CreatePort();
  103. X
  104. X
  105. Xstruct ConCom
  106. X{
  107. X    struct IOStdReq *ConWriteReq; /* I/O write request */
  108. X    struct IOStdReq *ConReadReq;  /* I/O read request */
  109. X    struct MsgPort *RdReplyPort;  /* pointer to ReplyPort for console read */
  110. X    struct timerequest *TimerMsg; /* If != NULL, timer is open */
  111. X};
  112. X
  113. X
  114. Xstatic struct ConCom *OpenConsole ( struct Window *window );
  115. Xstatic void CloseConsole ( struct ConCom *tty );
  116. Xstatic void StartConRead ( struct ConCom *tty );
  117. Xstatic int ConGetC ( struct ConCom *tty );
  118. Xstatic int ConLookC ( struct ConCom *tty );
  119. Xstatic void ConWrite ( struct ConCom *c, char *data, int length );
  120. X
  121. Xstatic struct ConCom *OpenConsole (struct Window *window)
  122. X{
  123. X    struct ConCom *tty;
  124. X    struct MsgPort *WrReplyPort, *TimerPort;
  125. X
  126. X    if ( tty = (struct ConCom *)
  127. X        AllocMem(sizeof(struct ConCom), MEMF_CLEAR | MEMF_PUBLIC) )
  128. X    {
  129. X
  130. X        if ( (WrReplyPort = CreatePort(0, 0)) /* reply port for write */
  131. X
  132. X            && (tty->RdReplyPort = CreatePort(0, 0)) /* reply port for read */
  133. X
  134. X            && (tty->ConWriteReq = CreateStdIO ( WrReplyPort ))
  135. X
  136. X            && (tty->ConReadReq = CreateStdIO ( tty->RdReplyPort)) )
  137. X        {
  138. X            tty->ConWriteReq->io_Data = (APTR) window;
  139. X            tty->ConWriteReq->io_Length = sizeof(struct Window);
  140. X
  141. X            if ( !(OpenDevice ( "console.device", 0, tty->ConWriteReq, 0 )) )
  142. X            {
  143. X                tty->ConReadReq->io_Device = tty->ConWriteReq->io_Device;
  144. X                tty->ConReadReq->io_Unit = tty->ConWriteReq->io_Unit;
  145. X
  146. X                /* Try to set up regular interrupts for ^C check */
  147. X                TimerPort = CreatePort(NULL, 0);
  148. X                if (
  149. X                    TimerPort
  150. X                    && ( tty->TimerMsg = (struct timerequest *)
  151. X                        CreateExtIO(TimerPort, sizeof(struct timerequest)) )
  152. X                    && !OpenDevice (TIMERNAME, UNIT_VBLANK,
  153. X                        (struct IORequest *)(tty->TimerMsg), 0)
  154. X                   )
  155. X                    return tty; /* All ok! */
  156. X                /* Main console ports ok, but no timer.  We'll live
  157. X                   without it...
  158. X                */
  159. X                if ( TimerPort ) DeletePort ( TimerPort );
  160. X                if ( tty->TimerMsg )
  161. X                    DeleteExtIO( (struct IORequest *)(tty->TimerMsg),
  162. X                        (long)sizeof(struct timerequest) );
  163. X                tty->TimerMsg = NULL;
  164. X                return tty;
  165. X            }
  166. X        }
  167. X
  168. X        /* If get here, something went wrong */
  169. X        if ( tty->ConReadReq ) DeleteStdIO(tty->ConReadReq);
  170. X        if ( tty->RdReplyPort ) DeletePort(tty->RdReplyPort);
  171. X        if ( tty->ConWriteReq ) DeleteStdIO(tty->ConWriteReq);
  172. X        if ( WrReplyPort ) DeletePort(WrReplyPort);
  173. X    }
  174. X    if ( tty )
  175. X        FreeMem(tty, sizeof(struct ConCom));
  176. X    return NULL;
  177. X
  178. X}
  179. X
  180. Xstatic void CloseConsole (struct ConCom *tty)
  181. X{
  182. X    struct MsgPort *mp;
  183. X
  184. X    AbortIO(tty->ConReadReq);    /* Abort any read in progress */
  185. X    CloseDevice(tty->ConWriteReq);   /* close console device */
  186. X
  187. X    mp = tty->ConWriteReq->io_Message.mn_ReplyPort;
  188. X
  189. X    DeleteStdIO(tty->ConWriteReq);
  190. X    DeletePort(mp);
  191. X
  192. X    mp = tty->ConReadReq->io_Message.mn_ReplyPort;
  193. X
  194. X    DeleteStdIO(tty->ConReadReq);
  195. X    DeletePort(mp);
  196. X
  197. X    if (tty->TimerMsg)
  198. X    {
  199. X        AbortIO((struct IORequest *)(tty->TimerMsg));
  200. X        CloseDevice((struct IORequest *)(tty->TimerMsg));
  201. X        DeletePort ( tty->TimerMsg->tr_node.io_Message.mn_ReplyPort );
  202. X        DeleteExtIO ( (struct IORequest *)(tty->TimerMsg),
  203. X            (long)sizeof(struct timerequest) );
  204. X    }
  205. X
  206. X    FreeMem(tty, sizeof(struct ConCom));
  207. X    return;
  208. X}
  209. X
  210. X/*  Request a timer interrupt in 0.25 seconds.  Use this to poll for ^C */
  211. X
  212. Xstatic void StartTtyTimer (void)
  213. X{
  214. X    if ( !tty->TimerMsg ) return;
  215. X    tty->TimerMsg->tr_node.io_Command = TR_ADDREQUEST;
  216. X    tty->TimerMsg->tr_time.tv_secs = 0;
  217. X    tty->TimerMsg->tr_time.tv_micro = 250000L;
  218. X    SendIO ( (struct IORequest *)(tty->TimerMsg) );
  219. X}
  220. X
  221. Xstatic char buffer; /* buffer for incoming console character */
  222. X
  223. X/* asynchronous console read request--must be called once before
  224. X   any ConGetC requests
  225. X*/
  226. X
  227. Xstatic void StartConRead (struct ConCom *tty)
  228. X{
  229. X    struct IOStdReq *conr;
  230. X
  231. X    conr = tty->ConReadReq;
  232. X    conr->io_Command = CMD_READ;
  233. X    conr->io_Length = 1;
  234. X    conr->io_Data = (APTR) &buffer;
  235. X    SendIO(conr);   /* asynchronous posting of a read request */
  236. X}
  237. X
  238. X/* Get a character from the console.
  239. X*/
  240. Xstatic int ConGetC (struct ConCom *tty)
  241. X{
  242. X    struct MsgPort *mp, *tp;
  243. X    struct IOStdReq *rddata;
  244. X    int temp;
  245. X    ULONG ReadMsgBit, ClockMsgBit, MsgBits;
  246. X
  247. X    mp = tty->RdReplyPort;    /* get the read reply port */
  248. X    ReadMsgBit = 1 << mp->mp_SigBit;
  249. X    if ( tty->TimerMsg )
  250. X    {
  251. X        tp = tty->TimerMsg->tr_node.io_Message.mn_ReplyPort;
  252. X        ClockMsgBit = 1 << tp->mp_SigBit;
  253. X    }
  254. X    else ClockMsgBit = 0;
  255. X    rddata = NULL;
  256. X    do /* Wait for a character.  Wake up periodically so that ^C works */
  257. X    {
  258. X        MsgBits = Wait(ReadMsgBit | ClockMsgBit);
  259. X        if ( MsgBits & ReadMsgBit )
  260. X            rddata = (struct IOStdReq *) GetMsg ( mp );
  261. X        if ( MsgBits & ClockMsgBit )
  262. X            if ( GetMsg (tp) )
  263. X            {
  264. X                StartTtyTimer();
  265. X                chkabort();
  266. X            }
  267. X    } while ( !rddata );
  268. X
  269. X    /* We've got a character... */
  270. X    temp = buffer;   /* get the character */
  271. X    StartConRead ( tty ); /* set up next read */
  272. X    return temp;
  273. X}
  274. X
  275. X/* See if a character is available at the console.
  276. X   If so, get it, else return -1.
  277. X*/
  278. Xstatic int ConLookC (struct ConCom *tty)
  279. X{
  280. X    struct MsgPort *mp;
  281. X    struct IOStdReq *rddata;
  282. X    int temp;
  283. X
  284. X    mp = tty->RdReplyPort;    /* get the read reply port */
  285. X    rddata = (struct IOStdReq *) GetMsg ( mp );
  286. X    if ( !rddata ) return -1;
  287. X
  288. X    /* We've got a character... */
  289. X    temp = buffer;   /* get the character */
  290. X    StartConRead ( tty ); /* set up next read */
  291. X    return temp;
  292. X}
  293. X
  294. X/* write a specified number of characters from a buffer to console device
  295. X*/
  296. Xstatic void ConWrite (struct ConCom *tty, char *data, int length)
  297. X{
  298. X    struct IOStdReq *wrdata;
  299. X
  300. X    wrdata = tty->ConWriteReq;
  301. X    wrdata->io_Command = CMD_WRITE;
  302. X    wrdata->io_Length = length;
  303. X    wrdata->io_Data = (APTR) data;
  304. X    DoIO(wrdata); /* waits until write completes before continuing */
  305. X}
  306. X
  307. X/****************************************************************/
  308. X
  309. X
  310. X
  311. X/*
  312. X * This routine gets called once, to set up the
  313. X * terminal channel.
  314. X */
  315. Xvoid ttopen (void)
  316. X{
  317. X        int wl, wt;   /* window upper left corner specification */
  318. X        static struct Screen __aligned WBScreen, *wbsdata;
  319. X        static int IsV2;
  320. X        static struct NewWindow NewLessWindow =
  321. X        {
  322. X            0, 0, 640, 200,     /* position & size (may be changed) */
  323. X            -1, -1,             /* pens */
  324. X            0,                  /* IDCMP */
  325. X            WINDOWDEPTH | WINDOWSIZING | WINDOWDRAG | WINDOWCLOSE | ACTIVATE
  326. X                | SMART_REFRESH | NOCAREREFRESH,
  327. X            NULL, NULL,         /* Gadgets, Checkmark */
  328. X            "Less 1.4Z:  h for help",
  329. X            NULL, NULL,         /* Use WB screen */
  330. X            W_MINWIDTH, W_MINHEIGHT, -1, -1,
  331. X            WBENCHSCREEN
  332. X        };
  333. X
  334. X        if (tty) return;
  335. X
  336. X
  337. X        if (GfxBase =  /* V2.0 + ? */
  338. X            (struct GfxBase *)OpenLibrary("graphics.library", 36) )
  339. X        {
  340. X            CloseLibrary ( GfxBase );
  341. X            IsV2 = 1;
  342. X            if ( !(wbsdata = LockPubScreen("Workbench")) )
  343. X            {
  344. X                error ( "Can't find Workbench screen" );
  345. X                quit();
  346. X            }
  347. X        }
  348. X        else
  349. X        {
  350. X            IsV2 = 0;
  351. X            if ( !GetScreenData ( &WBScreen, sizeof(struct Screen),
  352. X                WBENCHSCREEN, NULL ) )
  353. X            {
  354. X                error ( "Can't find Workbench screen" );
  355. X                quit();
  356. X            }
  357. X            wbsdata = &WBScreen;
  358. X        }
  359. X        if ( (wl = Wind_Spec[0]) < 0 ) wl += wbsdata->Width;
  360. X        if ( wl < 0 ) wl = 0;
  361. X        if ( wl > wbsdata->Width )
  362. X            wl = wbsdata->Width - W_MINWIDTH;
  363. X        if ( (wt = Wind_Spec[1]) < 0 ) wt += wbsdata->Height;
  364. X        if ( wt < 0 ) wt = 0;
  365. X        if ( wt > wbsdata->Height )
  366. X            wt = wbsdata->Height - W_MINHEIGHT;
  367. X        if ( wl < 0 || wt < 0 )
  368. X        {
  369. X            error ( "Window won't fit on screen" );
  370. X            quit();
  371. X        }
  372. X        NewLessWindow.LeftEdge = wl;
  373. X        NewLessWindow.TopEdge = wt;
  374. X
  375. X        NewLessWindow.Width = Wind_Spec[2];
  376. X        if ( NewLessWindow.Width <= 0 )
  377. X            NewLessWindow.Width += wbsdata->Width;
  378. X        if ( NewLessWindow.Width <= 0 )
  379. X            NewLessWindow.Width = 0;
  380. X        NewLessWindow.Height = Wind_Spec[3];
  381. X        if ( NewLessWindow.Height <= 0 )
  382. X            NewLessWindow.Height += wbsdata->Height;
  383. X        if ( NewLessWindow.Height <= 0 )
  384. X            NewLessWindow.Height = 0;
  385. X
  386. X        if ( NewLessWindow.Width < W_MINWIDTH )
  387. X            NewLessWindow.Width = W_MINWIDTH;
  388. X        if ( NewLessWindow.Height < W_MINHEIGHT )
  389. X            NewLessWindow.Height = W_MINHEIGHT;
  390. X
  391. X        if ( NewLessWindow.LeftEdge + NewLessWindow.Width > wbsdata->Width )
  392. X            NewLessWindow.Width = wbsdata->Width - NewLessWindow.LeftEdge;
  393. X        if ( NewLessWindow.TopEdge + NewLessWindow.Height > wbsdata->Height )
  394. X            NewLessWindow.Height = wbsdata->Height - NewLessWindow.TopEdge;
  395. X        if ( NewLessWindow.Width < W_MINWIDTH )
  396. X            NewLessWindow.LeftEdge = wbsdata->Width - W_MINWIDTH;
  397. X        if ( NewLessWindow.Height < W_MINHEIGHT )
  398. X            NewLessWindow.TopEdge = wbsdata->Height - W_MINHEIGHT;
  399. X        if ( NewLessWindow.LeftEdge < 0 || NewLessWindow.TopEdge < 0 )
  400. X        {
  401. X            error ( "Window won't fit on screen" );
  402. X            quit();
  403. X        }
  404. X
  405. X        if (IsV2)
  406. X            UnlockPubScreen(NULL, wbsdata);
  407. X        if (!(LessWindow = (struct Window *) OpenWindow (&NewLessWindow)) )
  408. X        {
  409. X            error ( "Can't open Less window" );
  410. X            quit();
  411. X        }
  412. X        if (!(tty = OpenConsole(LessWindow)))
  413. X        {
  414. X            error ( "Can't open console device" );
  415. X            quit();
  416. X        }
  417. X        StartConRead ( tty );
  418. X        if ( tty->TimerMsg ) StartTtyTimer();
  419. X        /* enable report of window resizeing and close gadget */
  420. X        ConWrite(tty, "\x9b\x31\x32;11{", 7);
  421. X}
  422. X
  423. X/* Request size of window information
  424. X*/
  425. Xvoid getrowcol (void)
  426. X{
  427. X    static unsigned char buf[16], *p;
  428. X
  429. X    if ( !tty) ttopen();
  430. X    ConWrite(tty, "\x9b\x30\x20\x71", 4); /* request current window size */
  431. X    p = buf;
  432. X    while ( (*p = ConGetC(tty)) != 0x9b ) /* nothing */;
  433. X    p++;
  434. X    do
  435. X    {
  436. X        *p = ConGetC(tty);
  437. X    } while ( p < &(buf[15]) && *p++ != '\x72' );
  438. X    *p = '\0';
  439. X    /* buf has "En;n;n;n|", where E is 0x9b, n is a decimal number */
  440. X
  441. X    p = buf+1;
  442. X    do
  443. X    {
  444. X        if ( p = strchr ( p, ';' ) ) p++; /* skip window position */
  445. X        else break;
  446. X        if ( p = strchr ( p, ';' ) ) p++;
  447. X        else break;
  448. X        nrow = atoi ( p );   /* window height */
  449. X        if ( p = strchr ( p, ';' ) ) p++;
  450. X        else break;
  451. X        ncol = atoi ( p );   /* window width */
  452. X    }   while (0); /* just once! */
  453. X
  454. X    /* arbitrary data integrity checks: */
  455. X    if ( nrow < 2 || nrow > 99 || ncol < 10 || ncol > 200 )
  456. X    {
  457. X        /* Window probably too small for the font chosen.  We may not
  458. X           be able to even write an error message in the window! */
  459. X        MyRequester ( "Screen/Font mismatch" );
  460. X        quit();
  461. X    }
  462. X}
  463. X
  464. X
  465. X
  466. X/*
  467. X * This function gets called just
  468. X * before we go back home to the command interpreter.
  469. X * On the Amiga it closes up the virtual terminal window.
  470. X */
  471. Xvoid ttclose (void)
  472. X{
  473. X        if (tty != (struct ConCom *) 0L) {
  474. X                CloseConsole(tty);
  475. X                CloseWindow(LessWindow);
  476. X        }
  477. X        tty = NULL;
  478. X        nrow = 0;
  479. X}
  480. X
  481. X
  482. X/*
  483. X * Read a character from the terminal,
  484. X * performing no editing and doing conditional echo
  485. X * but interpretting window resize and close gadget reports
  486. X */
  487. Xint do_echo = 1; /* echo flag */
  488. X
  489. Xint ttgetc (void)
  490. X{
  491. X        unsigned char c;        /* must be unsigned! */
  492. X
  493. X
  494. X        while ( (c = ConGetC(tty)) == '\x9b' )
  495. X        {
  496. X            switch (c = ConGetC(tty))
  497. X            {
  498. X            case '1': /* raw input event */
  499. X                if ( (c = ConGetC(tty)) == '1' )
  500. X                    quit();  /* close gadget */
  501. X                else if ( c == '2' )  /* window resize */
  502. X                {
  503. X                    while ( (c = ConGetC(tty)) != '|') /* nothing */;
  504. X                    winch();
  505. X                }
  506. X                break;
  507. X            case '?': /* Help key */
  508. X                if ( (c = ConGetC(tty)) == '~' ) return 'h';
  509. X                break;
  510. X            case 'A':
  511. X            case 'T': /* Arrow up */
  512. X                c = 'b';
  513. X                break;
  514. X            case 'B':
  515. X            case 'S': /* Arrow down */
  516. X                c = ' ';
  517. X                break;
  518. X            case 'D': /* Arrow left */
  519. X                c = 'k';
  520. X                break;
  521. X            case 'C': /* Arrow right */
  522. X                c = '\r';
  523. X                break;
  524. X            case ' ': /* Shifted left or right */
  525. X                if ( (c = ConGetC(tty)) == 'A' ) c = 'u';
  526. X                else c = 'd';
  527. X                break;
  528. X            default:
  529. X                continue;
  530. X            }
  531. X            break;
  532. X        }
  533. X        if ( c == 3 )
  534. X        {
  535. X            sigs |= 01;
  536. X            psignals();
  537. X            /* no return */
  538. X        }
  539. X        if (do_echo)
  540. X                ttwrite(&c, 1);
  541. X
  542. X        return ((int) c);
  543. X}
  544. X
  545. X/*
  546. X * Check for ^C in the tty window.  This routine will throw
  547. X * away any characters waiting in the tty input buffer.  Returns when
  548. X * there's nothing in the input queue or one of the following has been
  549. X * recognized:
  550. X *
  551. X *  Close gadget    (exits)
  552. X *  Window resize   (resets window and returns)
  553. X *  ^C              (sets sigs and returns)
  554. X */
  555. Xint chk_sigs (void)
  556. X{
  557. X    int c;
  558. X
  559. X    for (;;)
  560. X    {
  561. X        if ( (c = ConLookC(tty)) < 0 ) return sigs;
  562. X
  563. X        switch ( c )
  564. X        {
  565. X        case '\x9b': /* raw input event */
  566. X            if ( (c = ConGetC(tty)) != '1' ) break; /* unexpected raw input */
  567. X            if ( (c = ConGetC(tty)) == '1' )
  568. X                quit();  /* close gadget */
  569. X            else if ( c == '2' )  /* window resize */
  570. X            {
  571. X                while ( (c = ConGetC(tty)) != '|') /* nothing */;
  572. X                winch();
  573. X                return sigs;
  574. X            }
  575. X            break;
  576. X        case 3:
  577. X            sigs |= 01;
  578. X            return sigs;
  579. X        }
  580. X    }
  581. X}
  582. X
  583. X
  584. X
  585. X/*
  586. X * Write a buffer of characters to the display.
  587. X */
  588. Xvoid ttwrite (char *buffer, int length)
  589. X{
  590. X        ConWrite ( tty, buffer, length );
  591. X}
  592. X
  593. X/*
  594. X * Write a string to the terminal
  595. X */
  596. Xvoid ttputs (char *s)
  597. X{
  598. X        ConWrite ( tty, s, strlen(s) );
  599. X}
  600. X
  601. X/* fake termcap output */
  602. X/* This takes the place of the original tputs(x,y,z), using only the
  603. X   first parameter
  604. X */
  605. Xvoid Tputs (char *s)
  606. X{
  607. X        flush();
  608. X        if ( s ) ConWrite ( tty, s, strlen(s) );
  609. X}
  610. X
  611. X/*
  612. X * We may not have a window: display a message in a requester
  613. X */
  614. Xint MyRequester (char *s)
  615. X{
  616. X    static struct IntuiText __aligned
  617. X    Ok =
  618. X    {
  619. X        AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  620. X        AUTOLEFTEDGE, AUTOTOPEDGE,
  621. X        AUTOITEXTFONT,
  622. X        "Ok!",
  623. X        AUTONEXTTEXT
  624. X    },
  625. X    IMsg =
  626. X    {
  627. X        AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  628. X        AUTOLEFTEDGE, AUTOTOPEDGE + 20, /* Hope this is enough for default font */
  629. X        AUTOITEXTFONT,
  630. X        "",
  631. X        AUTONEXTTEXT
  632. X    },
  633. X    LessMsg =
  634. X    {
  635. X        AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  636. X        AUTOLEFTEDGE, AUTOTOPEDGE,
  637. X        AUTOITEXTFONT,
  638. X        "Less 1.4Z:",
  639. X        &IMsg
  640. X    };
  641. X
  642. X    IMsg.IText = s;
  643. X    return (int)AutoRequest(NULL, &LessMsg, &Ok, &Ok, NULL, NULL, 250, 80);
  644. X}
  645. END_OF_FILE
  646. if test 17649 -ne `wc -c <'Less1.4Z/src/io.c'`; then
  647.     echo shar: \"'Less1.4Z/src/io.c'\" unpacked with wrong size!
  648. fi
  649. # end of 'Less1.4Z/src/io.c'
  650. fi
  651. if test -f 'Less1.4Z/src/main.c' -a "${1}" != "-c" ; then 
  652.   echo shar: Will not clobber existing file \"'Less1.4Z/src/main.c'\"
  653. else
  654. echo shar: Extracting \"'Less1.4Z/src/main.c'\" \(16671 characters\)
  655. sed "s/^X//" >'Less1.4Z/src/main.c' <<'END_OF_FILE'
  656. X/*
  657. X * Entry point, initialization, miscellaneous routines.
  658. X */
  659. X
  660. X#ifdef AMIGA
  661. X/* Compile with -HPreHeader.q to get "less.h"! */
  662. X#else
  663. X#include "less.h"
  664. X#endif
  665. X
  666. X#include "position.h"
  667. X#include <setjmp.h>
  668. X#include <signal.h>
  669. X
  670. Xpublic int      ispipe;
  671. Xpublic jmp_buf  main_loop;
  672. Xpublic char *   first_cmd;
  673. Xpublic char *   every_first_cmd;
  674. Xpublic int      new_file;
  675. Xpublic int      is_tty;
  676. Xpublic char     current_file[FILENAME];
  677. Xpublic char     previous_file[FILENAME];
  678. Xpublic POSITION prev_pos;
  679. Xpublic int      any_display;
  680. Xpublic int      ac;
  681. Xpublic char **  av;
  682. Xpublic int      curr_ac;
  683. X#if LOGFILE
  684. Xpublic int      logfile = -1;
  685. Xpublic int      force_logfile = 0;
  686. Xpublic char *   namelogfile = NULL;
  687. X#endif
  688. X#if EDITOR
  689. Xpublic char *   editor;
  690. X#endif
  691. X
  692. Xextern int file;
  693. Xextern int nbufs;
  694. Xextern int sigs;
  695. Xextern int quit_at_eof;
  696. Xextern int p_nbufs, f_nbufs;
  697. Xextern int back_scroll;
  698. Xextern int top_scroll;
  699. Xextern int sc_height;
  700. Xextern int errmsgs;
  701. X
  702. X/* Prototypes for functions defined in main.c */
  703. X
  704. Xstatic void SeekRoot __PROTO((ULONG lock));
  705. X
  706. X
  707. X#ifdef AMIGA
  708. X/********** amiga **************/
  709. X#include <ctype.h>
  710. X#include <dos.h>
  711. X#include <intuition/intuition.h>
  712. X#include <exec/memory.h>
  713. X#include <ios1.h>
  714. X
  715. Xextern struct UFB _ufbs[];
  716. X
  717. X/* Used by SeekRoot */
  718. X#define MAXPATHSTRING 256
  719. Xstatic char    absDir[MAXPATHSTRING];
  720. X
  721. Xstruct IntuitionBase *IntuitionBase;
  722. Xstruct Remember *RememberKey;
  723. Xint called_from_WB = 0;
  724. X
  725. X
  726. X/* max items and chars that *.c can expand to */
  727. X#define MAXTEMPLATES 100
  728. Xpublic char     *local_argv[MAXTEMPLATES];
  729. Xpublic int      local_argc;
  730. X#endif
  731. X
  732. X/*
  733. X * Edit a new file.
  734. X * Filename "-" means standard input.
  735. X * No filename means the "current" file, from the command line.
  736. X */
  737. X#ifdef __STDC__
  738. Xvoid edit (register char *filename)
  739. X#else
  740. X        public void
  741. Xedit(filename)
  742. X        register char *filename;
  743. X#endif
  744. X{
  745. X        register int f;
  746. X        register char *m;
  747. X        POSITION initial_pos;
  748. X        char message[100];
  749. X        char tempfile[FILENAME];
  750. X        static int didpipe;
  751. X
  752. X        initial_pos = NULL_POSITION;
  753. X        if (filename == NULL || *filename == '\0')
  754. X        {
  755. X                if (curr_ac >= ac)
  756. X                {
  757. X                        error("No current file");
  758. X                        return;
  759. X                }
  760. X                filename = av[curr_ac];
  761. X        }
  762. X        if (strcmp(filename, "#") == 0)
  763. X        {
  764. X                if (*previous_file == '\0')
  765. X                {
  766. X                        error("no previous file");
  767. X                        return;
  768. X                }
  769. X                strtcpy(tempfile, previous_file, sizeof(tempfile));
  770. X                filename = tempfile;
  771. X                initial_pos = prev_pos;
  772. X        }
  773. X        if (strcmp(filename, "-") == 0)
  774. X        {
  775. X                /*
  776. X                 * Use standard input.
  777. X                 */
  778. X                if (didpipe)
  779. X                {
  780. X                        error("Can view standard input only once");
  781. X                        return;
  782. X                }
  783. X                f = 0;
  784. X#ifdef AMIGA
  785. X                /* get standard input */
  786. X                if ( !chkufb(0) ) /* if linked with tinymain, we get no stdin */
  787. X                {
  788. X                    _ufbs[0].ufbfh = Input();
  789. X                    _ufbs[0].ufbflg |= UFB_RA | O_RAW;
  790. X                    if ( !called_from_WB ) _ufbs[0].ufbflg |= UFB_NC;
  791. X                }
  792. X#endif
  793. X        } else if ((m = bad_file(filename, message, sizeof(message))) != NULL)
  794. X        {
  795. X                error(m);
  796. X                return;
  797. X        } else if ((f = open(filename, 0)) < 0)
  798. X        {
  799. X                error(errno_message(filename, message, sizeof(message)));
  800. X                return;
  801. X        }
  802. X
  803. X#ifdef AMIGA
  804. X/* SAS 5.10a isatty is broken; reports that pipe:x is a tty */
  805. X        if (isatty(f) && f==0)
  806. X#else
  807. X        if (isatty(f))
  808. X#endif
  809. X        {
  810. X                /*
  811. X                 * Not really necessary to call this an error,
  812. X                 * but if the control terminal (for commands)
  813. X                 * and the input file (for data) are the same,
  814. X                 * we get weird results at best.
  815. X                 */
  816. X                error("Can't take input from a terminal");
  817. X                if (f > 0)
  818. X                        close(f);
  819. X                return;
  820. X        }
  821. X
  822. X#if LOGFILE
  823. X        /*
  824. X         * If he asked for a log file and we have opened standard input,
  825. X         * create the log file.
  826. X         * We take care not to blindly overwrite an existing file.
  827. X         */
  828. X        end_logfile();
  829. X        if (f == 0 && namelogfile != NULL && is_tty)
  830. X        {
  831. X                int exists;
  832. X                int answer;
  833. X
  834. X                /*
  835. X                 * {{ We could use access() here. }}
  836. X                 */
  837. X                exists = open(namelogfile, 0);
  838. X                close(exists);
  839. X                exists = (exists >= 0);
  840. X
  841. X                if (exists && !force_logfile)
  842. X                {
  843. X                        static char w[] = "WARNING: log file exists: ";
  844. X                        strcpy(message, w);
  845. X                        strtcpy(message+sizeof(w)-1, namelogfile,
  846. X                                sizeof(message)-sizeof(w));
  847. X                        error(message);
  848. X                        answer = 'X';   /* Ask the user what to do */
  849. X                } else
  850. X                        answer = 'O';   /* Create the log file */
  851. X
  852. X        loop:
  853. X                switch (answer)
  854. X                {
  855. X                case 'O': case 'o':
  856. X                        logfile = creat(namelogfile, 0644);
  857. X                        break;
  858. X                case 'A': case 'a':
  859. X                        logfile = open(namelogfile, 1);
  860. X                        if (lseek(logfile, (offset_t)0, 2) < 0)
  861. X                        {
  862. X                                close(logfile);
  863. X                                logfile = -1;
  864. X                        }
  865. X                        break;
  866. X                case 'D': case 'd':
  867. X                        answer = 0;     /* Don't print an error message */
  868. X                        break;
  869. X                case 'q':
  870. X                        quit();
  871. X                default:
  872. X                        putstr("\n  Overwrite, Append, or Don't log? ");
  873. X                        answer = getchr();
  874. X                        putstr("\n");
  875. X                        flush();
  876. X                        goto loop;
  877. X                }
  878. X
  879. X                if (logfile < 0 && answer != 0)
  880. X                {
  881. X                        sprintf(message, "Cannot write to \"%s\"",
  882. X                                namelogfile);
  883. X                        error(message);
  884. X                }
  885. X        }
  886. X#endif
  887. X
  888. X        /*
  889. X         * We are now committed to using the new file.
  890. X         * Close the current input file and set up to use the new one.
  891. X         */
  892. X        if (file > 0)
  893. X                close(file);
  894. X        new_file = 1;
  895. X        strtcpy(previous_file, current_file, sizeof(previous_file));
  896. X        strtcpy(current_file, filename, sizeof(current_file));
  897. X        prev_pos = position(TOP);
  898. X#ifdef AMIGA
  899. X        /* Some heuristics to determine if we've been given a pipe.
  900. X           (there must be a better way...)
  901. X        */
  902. X        ispipe = ((f == 0) && !called_from_WB)
  903. X            || (strnicmp(filename, "pipe:", 5) == 0); /* kludge! */
  904. X#else
  905. X        ispipe = (f == 0);
  906. X#endif
  907. X        if (ispipe)
  908. X                didpipe = 1;
  909. X        file = f;
  910. X        ch_init( (ispipe) ? p_nbufs : f_nbufs );
  911. X        init_mark();
  912. X
  913. X        if (every_first_cmd != NULL)
  914. X                first_cmd = every_first_cmd;
  915. X
  916. X        if (is_tty)
  917. X        {
  918. X                int no_display = !any_display;
  919. X                any_display = 1;
  920. X                if (no_display && errmsgs > 0)
  921. X                {
  922. X                        /*
  923. X                         * We displayed some messages on error output
  924. X                         * (file descriptor 2; see error() function).
  925. X                         * Before erasing the screen contents,
  926. X                         * display the file name and wait for a keystroke.
  927. X                         */
  928. X                        error(filename);
  929. X                }
  930. X                /*
  931. X                 * Indicate there is nothing displayed yet.
  932. X                 */
  933. X                pos_clear();
  934. X                if (initial_pos != NULL_POSITION)
  935. X                        jump_loc(initial_pos);
  936. X        }
  937. X}
  938. X
  939. X/*
  940. X * Edit the next file in the command line list.
  941. X */
  942. X#ifdef __STDC__
  943. Xvoid next_file (int n)
  944. X#else
  945. X        public void
  946. Xnext_file(n)
  947. X        int n;
  948. X#endif
  949. X{
  950. X        if (curr_ac + n >= ac)
  951. X        {
  952. X                if (quit_at_eof)
  953. X                        quit();
  954. X                error("No (N-th) next file");
  955. X        } else
  956. X                edit(av[curr_ac += n]);
  957. X}
  958. X
  959. X/*
  960. X * Edit the previous file in the command line list.
  961. X */
  962. X#ifdef __STDC__
  963. Xvoid prev_file (int n)
  964. X#else
  965. X        public void
  966. Xprev_file(n)
  967. X        int n;
  968. X#endif
  969. X{
  970. X        if (curr_ac - n < 0)
  971. X                error("No (N-th) previous file");
  972. X        else
  973. X                edit(av[curr_ac -= n]);
  974. X}
  975. X
  976. X#ifndef AMIGA
  977. X/*
  978. X * Copy a file directly to standard output.
  979. X * Used if standard output is not a tty.
  980. X */
  981. X        static void
  982. Xcat_file()
  983. X{
  984. X        register int c;
  985. X
  986. X        while ((c = ch_forw_get()) != EOF)
  987. X                putchr(c);
  988. X        flush();
  989. X}
  990. X#endif
  991. X
  992. X
  993. X#ifdef AMIGA
  994. X/**************** amiga *****************************/
  995. X/* Bob Leivian  4/28/87 fudge up things so it will work
  996. X   when called from Work Bench */
  997. X
  998. Xchar argvbuf[80];
  999. X
  1000. X#include "workbench/startup.h"
  1001. X
  1002. X#ifdef MANX
  1003. X/* ignore AZTECs wb stuff */
  1004. X_wb_parse(ignore, ignore2)
  1005. Xchar *ignore;
  1006. Xchar *ignore2;
  1007. X{
  1008. X    return;
  1009. X}
  1010. X#endif
  1011. X#endif
  1012. X
  1013. X
  1014. X#ifdef NO_GETENV
  1015. X/* this requires the workbench disk --
  1016. X  ignore all environment variables for now */
  1017. Xchar * getenv(ignore)
  1018. X{
  1019. X        return NULL;
  1020. X}
  1021. X#endif
  1022. X
  1023. X/*
  1024. X * Entry point.
  1025. X */
  1026. X#ifdef __STDC__
  1027. Xint main (int argc, char **argv)
  1028. X#else
  1029. Xmain(argc, argv)
  1030. X        int argc;
  1031. X        char *argv[];
  1032. X#endif
  1033. X{
  1034. X        char *getenv();
  1035. X
  1036. X
  1037. X#ifdef AMIGA
  1038. X/***************** amiga ********************/
  1039. X        IntuitionBase = OpenLibrary ( "intuition.library", 0 );
  1040. X        RememberKey = NULL;
  1041. X        /* if we were called from the workbench we will have no args
  1042. X           but a pointer to WBstruct, get the filename from this structure */
  1043. X        if(argc == 0) {
  1044. X                struct WBStartup *WBmsg;
  1045. X                struct WBArg *p;
  1046. X                char *cp, c;
  1047. X                BPTR newlock;
  1048. X
  1049. X                /* the argv is really the work bench structure */
  1050. X                WBmsg = (struct WBStartup *) argv;
  1051. X                p = WBmsg->sm_ArgList;
  1052. X
  1053. X                /* fake up the args now */
  1054. X                /* argv[0] = p->wa_Name; */
  1055. X                p++; /* ignore first parm (name), since Less don't use it */
  1056. X                for ( local_argc = 1; local_argc < WBmsg->sm_NumArgs
  1057. X                    && local_argc < MAXTEMPLATES; local_argc++ )
  1058. X                {
  1059. X                    *absDir = '\0';
  1060. X                    /* SeekRoot UnLocks its argument */
  1061. X                    newlock = DupLock ( p->wa_Lock );
  1062. X                    SeekRoot ( newlock );
  1063. X                    /* The first part is really a device name */
  1064. X                    for ( cp=absDir; (c = *cp) && c != '/'; cp++ )
  1065. X                        /* nothing */;
  1066. X                    *cp = ':';
  1067. X                    if ( c == '\0' ) /* root dir of a device */
  1068. X                        *++cp = '\0';
  1069. X                    else
  1070. X                        strcat(cp, "/");
  1071. X                    if ( !(cp = AllocRemember(&RememberKey,
  1072. X                        strlen(absDir)+strlen(p->wa_Name)+1, 0L)) )
  1073. X                        quit();
  1074. X                    strcpy ( cp, absDir );
  1075. X                    local_argv[local_argc] = strcat(cp, p->wa_Name);
  1076. X                    p++;
  1077. X                }
  1078. X                local_argv[local_argc] = NULL;
  1079. X
  1080. X                called_from_WB = 1;
  1081. X        }
  1082. X
  1083. X
  1084. X#endif
  1085. X
  1086. X        /*
  1087. X         * Process command line arguments and LESS environment arguments.
  1088. X         * Command line arguments override environment arguments.
  1089. X         */
  1090. X        init_option();
  1091. X        scan_option(getenv("LESS"));
  1092. X        argv++;
  1093. X        while ( (--argc > 0) &&
  1094. X                (argv[0][0] == '-' || argv[0][0] == '+') &&
  1095. X                 argv[0][1] != '\0')
  1096. X                scan_option(*argv++);
  1097. X
  1098. X#if EDITOR
  1099. X        editor = getenv("EDITOR");
  1100. X        if (editor == NULL || *editor == '\0')
  1101. X                editor = "ed";
  1102. X#endif
  1103. X
  1104. X        /*
  1105. X         * Set up list of files to be examined.
  1106. X         */
  1107. X#ifdef AMIGA
  1108. X        if ( called_from_WB )
  1109. X        {
  1110. X            ac = local_argc-1;
  1111. X            av = local_argv+1; /* CLI case did an argv++ */
  1112. X        }
  1113. X        else
  1114. X        {
  1115. X#endif
  1116. X        ac = argc;
  1117. X        av = argv;
  1118. X#ifdef AMIGA
  1119. X        }
  1120. X#endif
  1121. X
  1122. X
  1123. X        curr_ac = 0;
  1124. X
  1125. X        /*
  1126. X         * Set up terminal, etc.
  1127. X         */
  1128. X#ifdef AMIGA
  1129. X        is_tty = 1;
  1130. X        ttopen();
  1131. X#else
  1132. X        is_tty = isatty(1);
  1133. X        if (!is_tty)
  1134. X        {
  1135. X                /*
  1136. X                 * Output is not a tty.
  1137. X                 * Just copy the input file(s) to output.
  1138. X                 */
  1139. X                if (ac < 1)
  1140. X                {
  1141. X                        edit("-");
  1142. X                        cat_file();
  1143. X                } else
  1144. X                {
  1145. X                        do
  1146. X                        {
  1147. X                                edit((char *)NULL);
  1148. X                                if (file >= 0)
  1149. X                                        cat_file();
  1150. X                        } while (++curr_ac < ac);
  1151. X                }
  1152. X                quit();
  1153. X        }
  1154. X#endif
  1155. X
  1156. X        raw_mode(1);
  1157. X        get_term();
  1158. X        open_getchr();
  1159. X        init();
  1160. X
  1161. X        if (setjmp(main_loop))
  1162. X                quit();
  1163. X        init_signals();
  1164. X
  1165. X        /*
  1166. X         * Select the first file to examine.
  1167. X         */
  1168. X        if (ac < 1)
  1169. X                edit("-");      /* Standard input */
  1170. X        else
  1171. X        {
  1172. X                /*
  1173. X                 * Try all the files named as command arguments.
  1174. X                 * We are simply looking for one which can be
  1175. X                 * opened without error.
  1176. X                 */
  1177. X                do
  1178. X                {
  1179. X                        edit((char *)NULL);
  1180. X                } while (file < 0 && ++curr_ac < ac);
  1181. X        }
  1182. X
  1183. X        if (file >= 0)
  1184. X                commands();
  1185. X        quit();
  1186. X        /*NOTREACHED*/
  1187. X}
  1188. X
  1189. X/*
  1190. X * Copy a string, truncating to the specified length if necessary.
  1191. X * Unlike strncpy(), the resulting string is guaranteed to be null-terminated.
  1192. X */
  1193. X#ifdef __STDC__
  1194. Xvoid strtcpy (char *to, char *from, int len)
  1195. X#else
  1196. Xstrtcpy(to, from, len)
  1197. X        char *to;
  1198. X        char *from;
  1199. X        int len;
  1200. X#endif
  1201. X{
  1202. X        strncpy(to, from, len);
  1203. X        to[len-1] = '\0';
  1204. X}
  1205. X
  1206. X/*
  1207. X * Exit the program.
  1208. X */
  1209. X#ifdef __STDC__
  1210. Xvoid quit (void)
  1211. X#else
  1212. X        public void
  1213. Xquit()
  1214. X#endif
  1215. X{
  1216. X        /*
  1217. X         * Put cursor at bottom left corner, clear the line,
  1218. X         * reset the terminal modes, and exit.
  1219. X         */
  1220. X#if LOGFILE
  1221. X        end_logfile();
  1222. X#endif
  1223. X#ifdef AMIGA
  1224. X        ttclose();
  1225. X
  1226. X        if (IntuitionBase)
  1227. X        {
  1228. X            FreeRemember( &RememberKey, 1 );
  1229. X            CloseLibrary(IntuitionBase);
  1230. X        }
  1231. X#else
  1232. X        lower_left();
  1233. X        clear_eol();
  1234. X        deinit();
  1235. X
  1236. X        flush();
  1237. X        raw_mode(0);
  1238. X
  1239. X#endif
  1240. X
  1241. X        exit(0);
  1242. X}
  1243. X
  1244. X
  1245. X#ifdef AMIGA
  1246. X
  1247. X/* Thanks to Bruce Rogers for a UseNet posting including the following
  1248. X   useful function...
  1249. X*/
  1250. X
  1251. X/*!*******************************************************************
  1252. X * FindRoot by Bruce Rogers 1/20/90
  1253. X *********************************************************************/
  1254. X/*
  1255. X------------------------------------------------------          Quantum _\/_
  1256. X2727 Eel                   Bruce (6502 RULES!) Rogers        |\  Duck  ( 0 0)
  1257. XDavis, Ca 95616            Quantum Duck Software,           |\ \______/ / \\\
  1258. X916-756-2684               rogers@iris.ucdavis.edu         |\ <  <     |   \/
  1259. X"My brain is on fire!"                                       \________/ Quark!
  1260. X
  1261. X*/
  1262. X
  1263. X
  1264. X/*!*******************************************************************
  1265. X * Recursively go up parent chain, looking for oldest parent.
  1266. X * Create the absolute path string as we go.
  1267. X *********************************************************************/
  1268. Xstatic void SeekRoot(lock)
  1269. XULONG   lock;
  1270. X{
  1271. Xstruct  FileInfoBlock   *fileInfo;
  1272. XULONG newlock;
  1273. Xchar NameEnd[MAXPATHSTRING], sep;
  1274. X
  1275. X    fileInfo=AllocMem(sizeof(struct FileInfoBlock),0);
  1276. X
  1277. X    Examine(lock,fileInfo);
  1278. X    strcpy ( NameEnd, absDir );
  1279. X    strcpy ( absDir, fileInfo->fib_FileName );
  1280. X    sep = 0; if ( *absDir ) sep = absDir[strlen(absDir) - 1];
  1281. X    if ( sep && *NameEnd && sep != '/' && sep != ':' ) strcat ( absDir, "/" );
  1282. X    strcat ( absDir, NameEnd );
  1283. X    newlock = ParentDir(lock);
  1284. X    UnLock(lock);
  1285. X    if (newlock!=NULL) SeekRoot(newlock);
  1286. X
  1287. X    FreeMem(fileInfo,sizeof(struct FileInfoBlock));
  1288. X}
  1289. X#endif
  1290. END_OF_FILE
  1291. if test 16671 -ne `wc -c <'Less1.4Z/src/main.c'`; then
  1292.     echo shar: \"'Less1.4Z/src/main.c'\" unpacked with wrong size!
  1293. fi
  1294. # end of 'Less1.4Z/src/main.c'
  1295. fi
  1296. if test -f 'Less1.4Z/src/screen.c' -a "${1}" != "-c" ; then 
  1297.   echo shar: Will not clobber existing file \"'Less1.4Z/src/screen.c'\"
  1298. else
  1299. echo shar: Extracting \"'Less1.4Z/src/screen.c'\" \(20275 characters\)
  1300. sed "s/^X//" >'Less1.4Z/src/screen.c' <<'END_OF_FILE'
  1301. X/*
  1302. X * Routines which deal with the characteristics of the terminal.
  1303. X * Uses termcap to be as terminal-independent as possible.
  1304. X *
  1305. X * {{ Someday this should be rewritten to use curses. }}
  1306. X */
  1307. X
  1308. X#ifdef AMIGA
  1309. X/* Compile with -HPreHeader.q to get "less.h"! */
  1310. X#else
  1311. X#include "less.h"
  1312. X#endif
  1313. X
  1314. X#if XENIX
  1315. X#include <sys/types.h>
  1316. X#include <sys/ioctl.h>
  1317. X#endif
  1318. X
  1319. X#ifdef AMIGA
  1320. Xextern int sc_window_spec;   /* user's requested -z */
  1321. Xextern int scroll; /* half-page scroll length */
  1322. Xextern int nrow, ncol;
  1323. X#else
  1324. X#if TERMIO
  1325. X#include <termio.h>
  1326. X#else
  1327. X#include <sgtty.h>
  1328. X#endif
  1329. X#endif
  1330. X
  1331. X#ifdef TIOCGWINSZ
  1332. X#include <sys/ioctl.h>
  1333. X#else
  1334. X/*
  1335. X * For the Unix PC (ATT 7300 & 3B1):
  1336. X * Since WIOCGETD is defined in sys/window.h, we can't use that to decide
  1337. X * whether to include sys/window.h.  Use SIGWIND from sys/signal.h instead.
  1338. X */
  1339. X#include <signal.h>
  1340. X#ifdef SIGWIND
  1341. X#include <sys/window.h>
  1342. X#endif
  1343. X#endif
  1344. X
  1345. X
  1346. X/*
  1347. X * Strings passed to tputs() to do various terminal functions.
  1348. X */
  1349. Xstatic char
  1350. X        *sc_pad,                /* Pad string */
  1351. X        *sc_home,               /* Cursor home */
  1352. X        *sc_addline,            /* Add line, scroll down following lines */
  1353. X        *sc_lower_left,         /* Cursor to last line, first column */
  1354. X        *sc_move,               /* General cursor positioning */
  1355. X        *sc_clear,              /* Clear screen */
  1356. X        *sc_eol_clear,          /* Clear to end of line */
  1357. X        *sc_s_in,               /* Enter standout (highlighted) mode */
  1358. X        *sc_s_out,              /* Exit standout mode */
  1359. X        *sc_u_in,               /* Enter underline mode */
  1360. X        *sc_u_out,              /* Exit underline mode */
  1361. X        *sc_b_in,               /* Enter bold mode */
  1362. X        *sc_b_out,              /* Exit bold mode */
  1363. X#ifdef AMIGA
  1364. X        *sc_it_in,              /* Enter italic mode */
  1365. X        *sc_it_out,             /* Exit italic mode */
  1366. X        *sc_nv_in,              /* Enter inverse video mode */
  1367. X        *sc_nv_out,             /* Exit inverse video mode */
  1368. X#endif
  1369. X        *sc_visual_bell,        /* Visual bell (flash screen) sequence */
  1370. X        *sc_backspace,          /* Backspace cursor */
  1371. X        *sc_init,               /* Startup terminal initialization */
  1372. X        *sc_deinit;             /* Exit terminal de-intialization */
  1373. X#ifdef DUMBTERM
  1374. Xstatic int dumb;
  1375. X#endif
  1376. Xstatic int hard;
  1377. X
  1378. Xpublic int auto_wrap;           /* Terminal does \r\n when write past margin */
  1379. Xpublic int ignaw;               /* Terminal ignores \n immediately after wrap */
  1380. Xpublic int erase_char, kill_char; /* The user's erase and line-kill chars */
  1381. Xpublic int sc_width, sc_height; /* Height & width of screen */
  1382. Xpublic int sc_window = -1;      /* window size for forward and backward */
  1383. Xpublic int bo_width, be_width;  /* Printing width of boldface sequences */
  1384. Xpublic int ul_width, ue_width;  /* Printing width of underline sequences */
  1385. Xpublic int so_width, se_width;  /* Printing width of standout sequences */
  1386. Xpublic int it_width, ie_width;  /* Printing width of italic sequences */
  1387. Xpublic int nv_width, ne_width;  /* Printing width of inv video sequences */
  1388. X
  1389. X/*
  1390. X * These two variables are sometimes defined in,
  1391. X * and needed by, the termcap library.
  1392. X * It may be necessary on some systems to declare them extern here.
  1393. X */
  1394. X/*extern*/ short ospeed;        /* Terminal output baud rate */
  1395. X/*extern*/ char PC;             /* Pad character */
  1396. X
  1397. Xextern int quiet;               /* If VERY_QUIET, use visual bell for bell */
  1398. X#ifdef DUMBTERM
  1399. Xextern int know_dumb;           /* Don't complain about a dumb terminal */
  1400. X#endif
  1401. Xextern int back_scroll;
  1402. Xchar *tgetstr();
  1403. Xchar *tgoto();
  1404. X
  1405. X/*
  1406. X * Change terminal to "raw mode", or restore to "normal" mode.
  1407. X * "Raw mode" means
  1408. X *      1. An outstanding read will complete on receipt of a single keystroke.
  1409. X *      2. Input is not echoed.
  1410. X *      3. On output, \n is mapped to \r\n.
  1411. X *      4. \t is NOT expanded into spaces.
  1412. X *      5. Signal-causing characters such as ctrl-C (interrupt),
  1413. X *         etc. are NOT disabled.
  1414. X * It doesn't matter whether an input \n is mapped to \r, or vice versa.
  1415. X */
  1416. X#ifdef __STDC__
  1417. Xvoid raw_mode (int on)
  1418. X#else
  1419. X        public void
  1420. Xraw_mode(on)
  1421. X        int on;
  1422. X#endif
  1423. X{
  1424. X#ifdef AMIGA
  1425. X        extern int do_echo;
  1426. X
  1427. X        if (on)
  1428. X                do_echo = 0;
  1429. X        else
  1430. X                do_echo = 1;
  1431. X        erase_char = 8; /* ^H */
  1432. X        kill_char = 24; /* ^X */
  1433. X#else
  1434. X#if TERMIO
  1435. X        struct termio s;
  1436. X        static struct termio save_term;
  1437. X
  1438. X        if (on)
  1439. X        {
  1440. X                /*
  1441. X                 * Get terminal modes.
  1442. X                 */
  1443. X                ioctl(2, TCGETA, &s);
  1444. X
  1445. X                /*
  1446. X                 * Save modes and set certain variables dependent on modes.
  1447. X                 */
  1448. X                save_term = s;
  1449. X                ospeed = s.c_cflag & CBAUD;
  1450. X                erase_char = s.c_cc[VERASE];
  1451. X                kill_char = s.c_cc[VKILL];
  1452. X
  1453. X                /*
  1454. X                 * Set the modes to the way we want them.
  1455. X                 */
  1456. X                s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
  1457. X                s.c_oflag |=  (OPOST|ONLCR|TAB3);
  1458. X                s.c_oflag &= ~(OCRNL|ONOCR|ONLRET);
  1459. X                s.c_cc[VMIN] = 1;
  1460. X                s.c_cc[VTIME] = 0;
  1461. X        } else
  1462. X        {
  1463. X                /*
  1464. X                 * Restore saved modes.
  1465. X                 */
  1466. X                s = save_term;
  1467. X        }
  1468. X        ioctl(2, TCSETAW, &s);
  1469. X#else
  1470. X        struct sgttyb s;
  1471. X        static struct sgttyb save_term;
  1472. X
  1473. X        if (on)
  1474. X        {
  1475. X                /*
  1476. X                 * Get terminal modes.
  1477. X                 */
  1478. X                ioctl(2, TIOCGETP, &s);
  1479. X
  1480. X                /*
  1481. X                 * Save modes and set certain variables dependent on modes.
  1482. X                 */
  1483. X                save_term = s;
  1484. X                ospeed = s.sg_ospeed;
  1485. X                erase_char = s.sg_erase;
  1486. X                kill_char = s.sg_kill;
  1487. X
  1488. X                /*
  1489. X                 * Set the modes to the way we want them.
  1490. X                 */
  1491. X                s.sg_flags |= CBREAK;
  1492. X                s.sg_flags &= ~(ECHO|XTABS);
  1493. X        } else
  1494. X        {
  1495. X                /*
  1496. X                 * Restore saved modes.
  1497. X                 */
  1498. X                s = save_term;
  1499. X        }
  1500. X        ioctl(2, TIOCSETN, &s);
  1501. X#endif
  1502. X#endif
  1503. X}
  1504. X
  1505. X#ifdef DUMBTERM
  1506. X        static void
  1507. Xcannot(s)
  1508. X        char *s;
  1509. X{
  1510. X        char message[100];
  1511. X
  1512. X        if (know_dumb)
  1513. X                /*
  1514. X                 * He knows he has a dumb terminal, so don't tell him.
  1515. X                 */
  1516. X                return;
  1517. X
  1518. X        sprintf(message, "WARNING: terminal cannot \"%s\"", s);
  1519. X        error(message);
  1520. X}
  1521. X#endif
  1522. X
  1523. X#ifdef AMIGA
  1524. X/*
  1525. X * Set forward and backward scrolling limits based upon user's requests
  1526. X * and screen size
  1527. X */
  1528. X#ifdef __STDC__
  1529. Xvoid set_scroll (void)
  1530. X#else
  1531. X        public void
  1532. Xset_scroll()
  1533. X#endif
  1534. X{
  1535. X        if (sc_window_spec > 0)
  1536. X            sc_window = (sc_window_spec < nrow? sc_window_spec: nrow - 1);
  1537. X        else
  1538. X            sc_window = nrow - 1;
  1539. X}
  1540. X#endif
  1541. X
  1542. X/*
  1543. X * Get terminal capabilities via termcap.
  1544. X */
  1545. X#ifdef __STDC__
  1546. Xvoid get_term (void)
  1547. X#else
  1548. X        public void
  1549. Xget_term()
  1550. X#endif
  1551. X{
  1552. X#ifdef AMIGA
  1553. X        static char go_to_home[10];
  1554. X
  1555. X        getrowcol(); /* find out window size */
  1556. X        scroll = nrow/2;
  1557. X        set_scroll();
  1558. X
  1559. X/* I didn't want to port termcap for now, but there is a version
  1560. X on fish #14 that someone might want to use */
  1561. X        sc_pad = "";                /* Pad string */
  1562. X        sc_home = "\x9b\x31;1H";           /* Cursor home */
  1563. X        sc_addline = "\x9bL";       /* Add line, scroll down following lines */
  1564. X        sprintf(go_to_home, "\x9b%d;1H", nrow);
  1565. X        sc_lower_left = go_to_home;     /* Cursor to last line, first column */
  1566. X        sc_move = "";               /* General cursor positioning */
  1567. X        sc_clear = "\f";            /* Clear screen */
  1568. X        sc_eol_clear = "\x9bK";     /* Clear to end of line */
  1569. X        sc_s_in = "\x9b\x37m";   /* Enter standout (highlighted) mode */
  1570. X        sc_s_out = "\x9b\x30m";         /* Exit standout mode */
  1571. X        sc_u_in = "\x9b\x34m";         /* Enter underline mode */
  1572. X        sc_u_out = "\x9b\x30m";         /* Exit underline mode */
  1573. X        sc_b_in = "\x9b\x31m";         /* Enter bold mode */
  1574. X        sc_b_out = "\x9b\x30m";       /* Exit bold mode */
  1575. X        sc_it_in = "\x9b\x33m";     /* Enter italic mode */
  1576. X        sc_it_out = "\x9b\x30m";    /* Exit italic mode */
  1577. X        sc_nv_in = "\x9b\x37m";     /* Enter inverse video mode */
  1578. X        sc_nv_out = "\x9b\x30m";    /* Exit inverse video mode */
  1579. X        /* We define visual_bell to be null, because on the Amiga the
  1580. X           ordinary BELL signal (^G) does a visual bell.  Thus, in the
  1581. X           Amiga version of Less, the user's choice is between a visual
  1582. X           bell (not quiet) and no indicator at all (quiet)
  1583. X        */
  1584. X        sc_visual_bell = NULL;    /* Visual bell (flash screen) sequence */
  1585. X        sc_backspace = "\b";      /* Backspace cursor */
  1586. X        sc_init = "";               /* Startup terminal initialization */
  1587. X        sc_deinit = "";             /* Exit terminal de-intialization */
  1588. X        sc_height = nrow;
  1589. X        sc_width = ncol;
  1590. X
  1591. X        so_width = 0;
  1592. X        it_width = ie_width = nv_width = ne_width =
  1593. X        be_width = bo_width = ue_width = ul_width = se_width = so_width;
  1594. X
  1595. X#else
  1596. X        char termbuf[2048];
  1597. X        char *sp;
  1598. X#ifdef TIOCGWINSZ
  1599. X        struct winsize w;
  1600. X#else
  1601. X#ifdef WIOCGETD
  1602. X        struct uwdata w;
  1603. X#endif
  1604. X#endif
  1605. X        static char sbuf[1024];
  1606. X
  1607. X        char *getenv();
  1608. X
  1609. X        /*
  1610. X         * Find out what kind of terminal this is.
  1611. X         */
  1612. X        if (tgetent(termbuf, getenv("TERM")) <= 0)
  1613. X                dumb = 1;
  1614. X
  1615. X        /*
  1616. X         * Get size of the screen.
  1617. X         */
  1618. X#ifdef TIOCGWINSZ
  1619. X        if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_row)
  1620. X                sc_height = w.ws_row;
  1621. X        else
  1622. X#else
  1623. X#ifdef WIOCGETD
  1624. X        if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_height)
  1625. X                sc_height = w.uw_height/w.uw_vs;
  1626. X        else
  1627. X#endif
  1628. X#endif
  1629. X                sc_height = tgetnum("li");
  1630. X        if (dumb || sc_height < 0 || tgetflag("hc"))
  1631. X        {
  1632. X                /* Oh no, this is a hardcopy terminal. */
  1633. X                hard = 1;
  1634. X                sc_height = 24;
  1635. X        }
  1636. X        /*
  1637. X         * This is terrible - the following if "knows" that it is being
  1638. X         * executed *after* command line and environment options have
  1639. X         * already been parsed.  Should it be executed in the main program
  1640. X         * instead?
  1641. X         */
  1642. X        if ((sc_window <= 0) || (sc_window >= sc_height))
  1643. X                sc_window = sc_height-1;
  1644. X
  1645. X#ifdef TIOCGWINSZ
  1646. X        if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_col)
  1647. X                sc_width = w.ws_col;
  1648. X        else
  1649. X#ifdef WIOCGETD
  1650. X        if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_width)
  1651. X                sc_width = w.uw_width/w.uw_hs;
  1652. X        else
  1653. X#endif
  1654. X#endif
  1655. X                sc_width = tgetnum("co");
  1656. X        if (dumb || sc_width < 0)
  1657. X                sc_width = 80;
  1658. X
  1659. X        auto_wrap = tgetflag("am");
  1660. X        ignaw = tgetflag("xn");
  1661. X
  1662. X        /*
  1663. X         * Assumes termcap variable "sg" is the printing width of
  1664. X         * the standout sequence, the end standout sequence,
  1665. X         * the underline sequence, the end underline sequence,
  1666. X         * the boldface sequence, and the end boldface sequence.
  1667. X         */
  1668. X        if ((so_width = tgetnum("sg")) < 0)
  1669. X                so_width = 0;
  1670. X        be_width = bo_width = ue_width = ul_width = se_width = so_width;
  1671. X
  1672. X        /*
  1673. X         * Get various string-valued capabilities.
  1674. X         */
  1675. X        sp = sbuf;
  1676. X
  1677. X        sc_pad = (dumb) ? NULL : tgetstr("pc", &sp);
  1678. X        if (sc_pad != NULL)
  1679. X                PC = *sc_pad;
  1680. X
  1681. X        sc_init = (dumb) ? NULL : tgetstr("ti", &sp);
  1682. X        if (sc_init == NULL)
  1683. X                sc_init = "";
  1684. X
  1685. X        sc_deinit= (dumb) ? NULL : tgetstr("te", &sp);
  1686. X        if (sc_deinit == NULL)
  1687. X                sc_deinit = "";
  1688. X
  1689. X        sc_eol_clear = (dumb) ? NULL : tgetstr("ce", &sp);
  1690. X        if (hard || sc_eol_clear == NULL || *sc_eol_clear == '\0')
  1691. X        {
  1692. X                cannot("clear to end of line");
  1693. X                sc_eol_clear = "";
  1694. X        }
  1695. X
  1696. X        sc_clear = (dumb) ? NULL : tgetstr("cl", &sp);
  1697. X        if (hard || sc_clear == NULL || *sc_clear == '\0')
  1698. X        {
  1699. X                cannot("clear screen");
  1700. X                sc_clear = "\n\n";
  1701. X        }
  1702. X
  1703. X        sc_move = (dumb) ? NULL : tgetstr("cm", &sp);
  1704. X        if (hard || sc_move == NULL || *sc_move == '\0')
  1705. X        {
  1706. X                /*
  1707. X                 * This is not an error here, because we don't
  1708. X                 * always need sc_move.
  1709. X                 * We need it only if we don't have home or lower-left.
  1710. X                 */
  1711. X                sc_move = "";
  1712. X        }
  1713. X
  1714. X        sc_s_in = (dumb) ? NULL : tgetstr("so", &sp);
  1715. X        if (hard || sc_s_in == NULL)
  1716. X                sc_s_in = "";
  1717. X
  1718. X        sc_s_out = (dumb) ? NULL : tgetstr("se", &sp);
  1719. X        if (hard || sc_s_out == NULL)
  1720. X                sc_s_out = "";
  1721. X
  1722. X        sc_u_in = (dumb) ? NULL : tgetstr("us", &sp);
  1723. X        if (hard || sc_u_in == NULL)
  1724. X                sc_u_in = sc_s_in;
  1725. X
  1726. X        sc_u_out = (dumb) ? NULL : tgetstr("ue", &sp);
  1727. X        if (hard || sc_u_out == NULL)
  1728. X                sc_u_out = sc_s_out;
  1729. X
  1730. X        sc_b_in = (dumb) ? NULL : tgetstr("md", &sp);
  1731. X        if (hard || sc_b_in == NULL)
  1732. X        {
  1733. X                sc_b_in = sc_s_in;
  1734. X                sc_b_out = sc_s_out;
  1735. X        } else
  1736. X        {
  1737. X                sc_b_out = (dumb) ? NULL : tgetstr("me", &sp);
  1738. X                if (hard || sc_b_out == NULL)
  1739. X                        sc_b_out = "";
  1740. X        }
  1741. X
  1742. X        sc_visual_bell = (dumb) ? NULL : tgetstr("vb", &sp);
  1743. X        if (hard || sc_visual_bell == NULL)
  1744. X                sc_visual_bell = "";
  1745. X
  1746. X        sc_home = (dumb) ? NULL : tgetstr("ho", &sp);
  1747. X        if (hard || sc_home == NULL || *sc_home == '\0')
  1748. X        {
  1749. X                if (*sc_move == '\0')
  1750. X                {
  1751. X                        cannot("home cursor");
  1752. X                        /*
  1753. X                         * This last resort for sc_home is supposed to
  1754. X                         * be an up-arrow suggesting moving to the
  1755. X                         * top of the "virtual screen". (The one in
  1756. X                         * your imagination as you try to use this on
  1757. X                         * a hard copy terminal.)
  1758. X                         */
  1759. X                        sc_home = "|\b^";
  1760. X                } else
  1761. X                {
  1762. X                        /*
  1763. X                         * No "home" string,
  1764. X                         * but we can use "move(0,0)".
  1765. X                         */
  1766. X                        strcpy(sp, tgoto(sc_move, 0, 0));
  1767. X                        sc_home = sp;
  1768. X                        sp += strlen(sp) + 1;
  1769. X                }
  1770. X        }
  1771. X
  1772. X        sc_lower_left = (dumb) ? NULL : tgetstr("ll", &sp);
  1773. X        if (hard || sc_lower_left == NULL || *sc_lower_left == '\0')
  1774. X        {
  1775. X                if (*sc_move == '\0')
  1776. X                {
  1777. X                        cannot("move cursor to lower left of screen");
  1778. X                        sc_lower_left = "\r";
  1779. X                } else
  1780. X                {
  1781. X                        /*
  1782. X                         * No "lower-left" string,
  1783. X                         * but we can use "move(0,last-line)".
  1784. X                         */
  1785. X                        strcpy(sp, tgoto(sc_move, 0, sc_height-1));
  1786. X                        sc_lower_left = sp;
  1787. X                        sp += strlen(sp) + 1;
  1788. X                }
  1789. X        }
  1790. X
  1791. X        /*
  1792. X         * To add a line at top of screen and scroll the display down,
  1793. X         * we use "al" (add line) or "sr" (scroll reverse).
  1794. X         */
  1795. X        if (dumb)
  1796. X                sc_addline = NULL;
  1797. X        else if ((sc_addline = tgetstr("al", &sp)) == NULL ||
  1798. X                 *sc_addline == '\0')
  1799. X                sc_addline = tgetstr("sr", &sp);
  1800. X
  1801. X        if (hard || sc_addline == NULL || *sc_addline == '\0')
  1802. X        {
  1803. X                cannot("scroll backwards");
  1804. X                sc_addline = "";
  1805. X                /* Force repaint on any backward movement */
  1806. X                back_scroll = 0;
  1807. X        }
  1808. X
  1809. X        if (dumb || tgetflag("bs"))
  1810. X                sc_backspace = "\b";
  1811. X        else
  1812. X        {
  1813. X                sc_backspace = tgetstr("bc", &sp);
  1814. X                if (sc_backspace == NULL || *sc_backspace == '\0')
  1815. X                        sc_backspace = "\b";
  1816. X        }
  1817. X#endif
  1818. X}
  1819. X
  1820. X
  1821. X/*
  1822. X * Below are the functions which perform all the
  1823. X * terminal-specific screen manipulation.
  1824. X */
  1825. X
  1826. X
  1827. X/*
  1828. X * Initialize terminal
  1829. X */
  1830. X#ifdef __STDC__
  1831. Xvoid init (void)
  1832. X#else
  1833. X        public void
  1834. Xinit()
  1835. X#endif
  1836. X{
  1837. X        tputs(sc_init, sc_height, putchr);
  1838. X}
  1839. X
  1840. X/*
  1841. X * Deinitialize terminal
  1842. X */
  1843. X#ifdef __STDC__
  1844. Xvoid deinit (void)
  1845. X#else
  1846. X        public void
  1847. Xdeinit()
  1848. X#endif
  1849. X{
  1850. X        tputs(sc_deinit, sc_height, putchr);
  1851. X}
  1852. X
  1853. X/*
  1854. X * Home cursor (move to upper left corner of screen).
  1855. X */
  1856. X#ifdef __STDC__
  1857. Xvoid home (void)
  1858. X#else
  1859. X        public void
  1860. Xhome()
  1861. X#endif
  1862. X{
  1863. X        tputs(sc_home, 1, putchr);
  1864. X}
  1865. X
  1866. X/*
  1867. X * Add a blank line (called with cursor at home).
  1868. X * Should scroll the display down.
  1869. X */
  1870. X#ifdef __STDC__
  1871. Xvoid add_line (void)
  1872. X#else
  1873. X        public void
  1874. Xadd_line()
  1875. X#endif
  1876. X{
  1877. X        tputs(sc_addline, sc_height, putchr);
  1878. X}
  1879. X
  1880. X/*
  1881. X * Move cursor to lower left corner of screen.
  1882. X */
  1883. X#ifdef __STDC__
  1884. Xvoid lower_left (void)
  1885. X#else
  1886. X        public void
  1887. Xlower_left()
  1888. X#endif
  1889. X{
  1890. X        tputs(sc_lower_left, 1, putchr);
  1891. X}
  1892. X
  1893. X/*
  1894. X * Ring the terminal bell.
  1895. X */
  1896. X#ifdef __STDC__
  1897. Xvoid bell (void)
  1898. X#else
  1899. X        public void
  1900. Xbell()
  1901. X#endif
  1902. X{
  1903. X        if (quiet == VERY_QUIET)
  1904. X                vbell();
  1905. X        else
  1906. X                putchr('\7');
  1907. X}
  1908. X
  1909. X/*
  1910. X * Output the "visual bell", if there is one.
  1911. X */
  1912. X#ifdef __STDC__
  1913. Xvoid vbell (void)
  1914. X#else
  1915. X        public void
  1916. Xvbell()
  1917. X#endif
  1918. X{
  1919. X        if (*sc_visual_bell == '\0')
  1920. X                return;
  1921. X        tputs(sc_visual_bell, sc_height, putchr);
  1922. X}
  1923. X
  1924. X/*
  1925. X * Clear the screen.
  1926. X */
  1927. X#ifdef __STDC__
  1928. Xvoid clear (void)
  1929. X#else
  1930. X        public void
  1931. Xclear()
  1932. X#endif
  1933. X{
  1934. X        tputs(sc_clear, sc_height, putchr);
  1935. X}
  1936. X
  1937. X/*
  1938. X * Clear from the cursor to the end of the cursor's line.
  1939. X * {{ This must not move the cursor. }}
  1940. X */
  1941. X#ifdef __STDC__
  1942. Xvoid clear_eol (void)
  1943. X#else
  1944. X        public void
  1945. Xclear_eol()
  1946. X#endif
  1947. X{
  1948. X        tputs(sc_eol_clear, 1, putchr);
  1949. X}
  1950. X
  1951. X/*
  1952. X * Begin "standout" (bold, underline, or whatever).
  1953. X */
  1954. X#ifdef __STDC__
  1955. Xvoid so_enter (void)
  1956. X#else
  1957. X        public void
  1958. Xso_enter()
  1959. X#endif
  1960. X{
  1961. X        tputs(sc_s_in, 1, putchr);
  1962. X}
  1963. X
  1964. X/*
  1965. X * End "standout".
  1966. X */
  1967. X#ifdef __STDC__
  1968. Xvoid so_exit (void)
  1969. X#else
  1970. X        public void
  1971. Xso_exit()
  1972. X#endif
  1973. X{
  1974. X        tputs(sc_s_out, 1, putchr);
  1975. X}
  1976. X
  1977. X/*
  1978. X * Begin "underline" (hopefully real underlining,
  1979. X * otherwise whatever the terminal provides).
  1980. X */
  1981. X#ifdef __STDC__
  1982. Xvoid ul_enter (void)
  1983. X#else
  1984. X        public void
  1985. Xul_enter()
  1986. X#endif
  1987. X{
  1988. X        tputs(sc_u_in, 1, putchr);
  1989. X}
  1990. X
  1991. X/*
  1992. X * End "underline".
  1993. X */
  1994. X#ifdef __STDC__
  1995. Xvoid ul_exit (void)
  1996. X#else
  1997. X        public void
  1998. Xul_exit()
  1999. X#endif
  2000. X{
  2001. X        tputs(sc_u_out, 1, putchr);
  2002. X}
  2003. X
  2004. X/*
  2005. X * Begin "bold"
  2006. X */
  2007. X#ifdef __STDC__
  2008. Xvoid bo_enter (void)
  2009. X#else
  2010. X        public void
  2011. Xbo_enter()
  2012. X#endif
  2013. X{
  2014. X        tputs(sc_b_in, 1, putchr);
  2015. X}
  2016. X
  2017. X/*
  2018. X * End "bold".
  2019. X */
  2020. X#ifdef __STDC__
  2021. Xvoid bo_exit (void)
  2022. X#else
  2023. X        public void
  2024. Xbo_exit()
  2025. X#endif
  2026. X{
  2027. X        tputs(sc_b_out, 1, putchr);
  2028. X}
  2029. X
  2030. X#ifdef AMIGA
  2031. X/*
  2032. X * Begin "italic" mode
  2033. X */
  2034. X#ifdef __STDC__
  2035. Xvoid it_enter (void)
  2036. X#else
  2037. X        public void
  2038. Xit_enter()
  2039. X#endif
  2040. X{
  2041. X        tputs(sc_it_in, 1, putchr);
  2042. X}
  2043. X
  2044. X/*
  2045. X * End "italic"
  2046. X */
  2047. X#ifdef __STDC__
  2048. Xvoid it_exit (void)
  2049. X#else
  2050. X        public void
  2051. Xit_exit()
  2052. X#endif
  2053. X{
  2054. X        tputs(sc_it_out, 1, putchr);
  2055. X}
  2056. X
  2057. X/*
  2058. X * Begin "inverse video"
  2059. X */
  2060. X#ifdef __STDC__
  2061. Xvoid nv_enter (void)
  2062. X#else
  2063. X        public void
  2064. Xnv_enter()
  2065. X#endif
  2066. X{
  2067. X        tputs(sc_nv_in, 1, putchr);
  2068. X}
  2069. X
  2070. X/*
  2071. X * End "inverse video"
  2072. X */
  2073. X#ifdef __STDC__
  2074. Xvoid nv_exit (void)
  2075. X#else
  2076. X        public void
  2077. Xnv_exit()
  2078. X#endif
  2079. X{
  2080. X        tputs(sc_nv_out, 1, putchr);
  2081. X}
  2082. X#endif
  2083. X
  2084. X/*
  2085. X * Erase the character to the left of the cursor
  2086. X * and move the cursor left.
  2087. X */
  2088. X#ifdef __STDC__
  2089. Xvoid backspace (void)
  2090. X#else
  2091. X        public void
  2092. Xbackspace()
  2093. X#endif
  2094. X{
  2095. X        /*
  2096. X         * Try to erase the previous character by overstriking with a space.
  2097. X         */
  2098. X        tputs(sc_backspace, 1, putchr);
  2099. X        putchr(' ');
  2100. X        tputs(sc_backspace, 1, putchr);
  2101. X}
  2102. X
  2103. X/*
  2104. X * Output a plain backspace, without erasing the previous char.
  2105. X */
  2106. X#ifdef __STDC__
  2107. Xvoid putbs (void)
  2108. X#else
  2109. X        public void
  2110. Xputbs()
  2111. X#endif
  2112. X{
  2113. X        tputs(sc_backspace, 1, putchr);
  2114. X}
  2115. END_OF_FILE
  2116. if test 20275 -ne `wc -c <'Less1.4Z/src/screen.c'`; then
  2117.     echo shar: \"'Less1.4Z/src/screen.c'\" unpacked with wrong size!
  2118. fi
  2119. # end of 'Less1.4Z/src/screen.c'
  2120. fi
  2121. echo shar: End of archive 3 \(of 7\).
  2122. cp /dev/null ark3isdone
  2123. MISSING=""
  2124. for I in 1 2 3 4 5 6 7 ; do
  2125.     if test ! -f ark${I}isdone ; then
  2126.     MISSING="${MISSING} ${I}"
  2127.     fi
  2128. done
  2129. if test "${MISSING}" = "" ; then
  2130.     echo You have unpacked all 7 archives.
  2131.     rm -f ark[1-9]isdone
  2132. else
  2133.     echo You still need to unpack the following archives:
  2134.     echo "        " ${MISSING}
  2135. fi
  2136. ##  End of shell archive.
  2137. exit 0
  2138. -- 
  2139. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  2140. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  2141. Post requests for sources, and general discussion to comp.sys.amiga.misc.
  2142.